#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      Pablo
#
# Created:     14/03/2012
# Copyright:   (c) Monxcleyr Productions 2012
# Licence:     GPL v3
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import config
import os

class Keys():
  """Class for loading up and saving keybindings."""

  def __init__(self):
    self.bind = {}
    self.default = {}
    self.conf = config.Config()
    self.conf.read(os.path.join('Settings/keys.ini'))
    self.load()


  def load(self):

    """ Reload keybindings."""

    options = self.conf.options('Keys')
    templist = []

    for i in range(0, len(options)):
      tempvalue = self.conf.getint('Keys', options[i])
      templist.append((options[i], tempvalue))

    self.bind = dict(templist)

#-------------------------------------------------------------------------------

    self.conf.read(os.path.join('resources/configs/default keys.ini'))

    options = self.conf.options('Keys')
    templist = []

    for i in range(0, len(options)):
      tempvalue = self.conf.getint('Keys', options[i])
      templist.append((options[i], tempvalue))

    # dict of default keys
    self.default = dict(templist)

  def save(self):

    """ Saves Keybindings. """

    for key in self.bind:
      self.conf.set('Keys', key, self.bind[key])

##    for key in self.default:
##      self.conf.set('Defaults', key, self.default[key])

    with open(os.path.join('resources/configs/keys.ini'), 'w') as configfile:
##      configfile.write("# Don't edit [Defaults]. \n")
      self.conf.write(configfile)
